/**
 * Created by tdzl2003 on 7/28/16.
 */

import { FORBIDDEN } from '../utils/StatusError';

const PUSH_NAMES = {
  push_hooks: 'push',
}

export default function (body, config) {
  const info = JSON.parse(body.hook);
  if (info.password !== config.password) {
    throw FORBIDDEN;
  }

  return {
    action: PUSH_NAMES[info.hook_name] || 'unknown',
    name: info.push_data.ref,
  }
}
